function rankings = parseRankings(filename)

% PARSERANKINGS - parse a csv ranking file

    fid = fopen(filename);
    if fid < 0
        rankings = [];
        return;
    end
    count = 1;
    tline = fgetl(fid);
    [n,p,t,b,r,i,q,Q,t,T,k,K,d,D] = ...
        strread(tline,'%s%s%s%s%s%s%s%s%s%s%s%s%s%s','delimiter',',');
    while 1
        tline = fgetl(fid);
        if ~ischar(tline), break, end
        [n,p,t,b,r,i] = strread(tline,'%s%s%s%s%s%s','delimiter',',');
        name{count} = n{1};
        pos(count) = positionNum(p{1});
        team{count} = t{1};
        bye(count) = str2double(b{1});
        rank(count) = str2double(r{1});
        id(count) = str2double(i{1});
        count = count + 1;
    end

    rankings.name = name;
    rankings.pos = pos;
    rankings.team = team;
    rankings.bye = bye;
    rankings.rank = rank;
    rankings.id = id;
    rankings.MAX_QB = str2double(Q{1});
    rankings.MAX_TE = str2double(T{1});
    rankings.MAX_K = str2double(K{1});
    rankings.MAX_DST = str2double(D{1});
    
end

function n = positionNum(posstr)
    
    if strcmpi(posstr,'RB')
        n = 1;
    elseif strcmpi(posstr,'QB')
        n = 2;
    elseif strcmpi(posstr,'WR')
        n = 3;
    elseif strcmpi(posstr,'TE')
        n = 4;
    elseif strcmpi(posstr,'K')
        n = 5;
    elseif strcmpi(posstr,'DST')
        n = 6;
    else
        error('unknown position string');
    end
end
